#import "TestView.h"


@implementation TestView


- (void) adjustFrame
{
    NSRect frame = NSZeroRect;
    frame.size.width = 300;
    frame.size.height = 200;

    [self setFrame: frame];
    [self setNeedsDisplay: YES];

} // adjustFrame


- (void) awakeFromNib
{
    [self adjustFrame];
} // awakeFromNib


- (void) drawBadge: (int) count
{
    NSDictionary *attributes;
    attributes = [NSDictionary dictionaryWithObjectsAndKeys:
                                   NSFontSizeAttribute,
                               [NSNumber numberWithInt: 45], nil];

    NSString *string = [NSString stringWithFormat: @"%d", count];

    NSSize size;
    size = [string sizeWithAttributes: attributes];

    NSRect bounds = [self bounds];
    
    NSPoint stringPoint;
    stringPoint.x = bounds.origin.x + bounds.size.width - size.width;
    stringPoint.y = bounds.origin.y + bounds.size.height - size.height;

    NSRect cornerRect;
    cornerRect.origin = stringPoint;
    cornerRect.size = size;

    [[NSColor whiteColor] set];
    [NSBezierPath fillRect: cornerRect];

    [string drawAtPoint: stringPoint
            withAttributes: attributes];

} // drawBadge


- (void) drawRect: (NSRect) rect
{
    rect = [self bounds];

#if 0
    NSLog (@"drawing %p", self);
    NSLog (@"   bounds: %@", NSStringFromRect([self bounds]));
    NSLog (@"   frame: %@", NSStringFromRect([self frame]));
#endif

    [[NSColor lightGrayColor] set];
    [NSBezierPath fillRect: rect];

    static int s_count = 1;
    [self drawBadge: s_count];
    s_count++;

    [[NSColor blackColor] set];
    [NSBezierPath strokeRect: rect];

} // drawRect


- (void) mouseDown: (NSEvent *) event
{
    NSLog (@"clicky clicky!");
} // mouseDown

@end // TestView

